// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ForgePrettyPrinter.cs" company="Open Trader">
//   Copyright (c) David Denis (david.denis@systemathics.com)
// </copyright>
// <summary>
//   |  Open Trader - The Open Source Systematic Trading Platform
//   |
//   |  This program is free software: you can redistribute it and/or modify
//   |  it under the terms of the GNU General Public License as published by
//   |  the Free Software Foundation, either version 2 of the License, or
//   |  (at your option) any later version.
//   |
//   |  This program is distributed in the hope that it will be useful,
//   |  but WITHOUT ANY WARRANTY; without even the implied warranty of
//   |  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//   |  GNU General Public License for more details.
//   |
//   |  You should have received a copy of the GNU General Public License
//   |  along with this program.  If not, see http://www.gnu.org/licenses
//   |
//   |  Up to date informations about Open Trader can be found at :
//   |    http://opentrader.org
//   |    http://opentrader.codeplex.com
//   |
//   |  For professional services, please visit us at :
//   |    http://www.systemathics.com
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Org.OpenTrader.Framework.Forge
{
    #region Using Directives

    using System;

    using Org.OpenTrader.Framework.Forge.Enums;

    #endregion

    /// <summary>
    /// The forge pretty printer.
    /// </summary>
    public class ForgePrettyPrinter
    {
        /// <summary>
        /// The prices.
        /// </summary>
        public class Prices
        {
            #region Public Methods

            /// <summary>
            /// The format.
            /// </summary>
            /// <param name="source">
            /// The source.
            /// </param>
            /// <param name="ticks">
            /// The ticks.
            /// </param>
            /// <returns>
            /// The format.
            /// </returns>
            public static string Format(double source, double ticks)
            {
                if (double.IsNaN(source))
                {
                    return "-";
                }

                if (ticks <= 0.0)
                {
                    ticks = Constants.Zero;
                }

                // Sorry this is not beutiful : )
                //var format = "{" + String.Format("0:0.{0}", "0000000000000000".Substring(0, (int)-Math.Log10(ticks))) + "}";
                var format = "{" + String.Format("0:0.{0}", "0000000000000000".Substring(0, (int)Math.Ceiling(-Math.Log10(ticks)))) + "}";
                var a = string.Format(format, source);
                return a;
            }

            /// <summary>
            /// The round.
            /// </summary>
            /// <param name="source">
            /// The source.
            /// </param>
            /// <param name="ticks">
            /// The ticks.
            /// </param>
            /// <param name="type">
            /// The type.
            /// </param>
            /// <returns>
            /// The round.
            /// </returns>
            public static double Round(double source, double ticks, ERoundType type)
            {
                var n = source;
                switch (type)
                {
                    case ERoundType.Up:
                        n = Math.Round(source, (int)-Math.Log10(ticks));
                        break;

                    case ERoundType.Down:
                        n = Math.Round(source, (int)-Math.Log10(ticks));
                        break;

                    default:
                        break;
                }

                return n;
            }

            #endregion
        }

        /// <summary>
        /// The sizes.
        /// </summary>
        public class Sizes
        {
            #region Public Methods

            /// <summary>
            /// The format.
            /// </summary>
            /// <param name="source">
            /// The source.
            /// </param>
            /// <returns>
            /// The format.
            /// </returns>
            public static string Format(int source)
            {
                if (source <= 0)
                {
                    return "-";
                }

                return string.Empty + source;
            }

            #endregion
        }
    }
}